package com.young.controller;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class MainController {

	@Autowired
	private HttpSession session;
	
	
	@RequestMapping({"","/","index"})
	public String index(){
		return "redirect:/person/";
	}
	
	
	@GetMapping("/login")
	public String login(){
		return "login";
	}
	
	
	@PostMapping("/login")
	public String login(String username, String password, Map<String,String> map){
		if("admin".equals(username) && "admin".equals(password)){
			session.setAttribute("currentuser", username);
			return "redirect:/person/";
		}else{
			map.put("msg", "请输入正确的用户名和密码！！！");
			return "login";
		}
	}
	
	
	@RequestMapping("/logout")
	public String logout(){
		session.removeAttribute("currentuser");
		return "login";
	}
	
	
	@RequestMapping("/about")
	public String about(){
		return "about";
	}
	
	
	@PostMapping("/upload")
	public String upload(MultipartFile file){
		System.out.println("file:::"+file);
		return "success";
	}
}
